<template>
  <view class="Mall4j">
    <!-- 商品详情 -->
    <view v-if="!commentShow" class="container">
      <!-- 轮播图 -->
      <view class="swiper-con">
        <view v-if="video && isPlaying" class="video-container">
          <video id="myVideo" enable-progress-gesture="false" objectFit="fill" :src="video" controls @ended="playEnd" />
        </view>
        <view v-if="video" class="play-btn" @tap="videoOper">
          <image v-if="!isPlaying" class="play-icon" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/play-red.png" />
          <text v-if="isPlaying" :class="'play-text ' + (isPlaying?'video-stop':'video-play')">
            {{ isPlaying ? i18n.quitPlaying : '' }}
          </text>
        </view>
        <swiper v-if="!isPlaying" :indicator-dots="indicatorDots" :indicator-color="indicatorColor" :interval="interval" :duration="duration" :indicator-active-color="indicatorActiveColor">
          <block v-if="imgs.length">
            <swiper-item v-for="(item, swiperIndex) in imgs" :key="swiperIndex">
              <image :src="item" />
            </swiper-item>
          </block>
          <swiper-item v-else>
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/def.png" mode="aspectFit" />
          </swiper-item>
        </swiper>
      </view>
      <!-- 轮播图end -->
      <!-- 倒计时栏 -->
      <view v-if="isGroupProd" class="countdown-box">
        <!-- 拼团 -->
        <text class="second-kill">{{ i18n.aGroup }}</text>
        <view class="countdown-content">
          <text v-if="groupActivity.activityStatus === 1" class="countdown-tips">{{ i18n.onlyStart }}</text>
          <text v-if="groupActivity.activityStatus !== 1" class="countdown-tips">{{ i18n.onlyEnd }}</text>
          <!-- <text class="countdown-time">{{endOfGroupTime.day}} {{i18n.day}} {{endOfGroupTime.hou}} {{i18n.time}} {{endOfGroupTime.min}} {{i18n.minute}}	{{endOfGroupTime.sec}} {{i18n.second}}</text> -->
          <text class="countdown-time">{{ endOfGroupTime.day }}
            <text class="countdown-tips">{{ i18n.day }}</text>
            {{ endOfGroupTime.hou }}:{{ endOfGroupTime.min }}:{{ endOfGroupTime.sec }}
          </text>
        </view>
      </view>
      <!-- 商品信息 -->
      <!--      <view class="prod-info">-->
      <!--        <view class="tit-wrap">-->
      <!--          <view class="prod-tit">{{ prodName }}</view>-->
      <!--          <view class="col" @tap="addOrCannelCollection">-->
      <!--            <image v-if="!isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col.png" />-->
      <!--            <image v-if="isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col-red.png" />{{ i18n.collection }}-->
      <!--          </view>-->
      <!--        </view>-->
      <!--        <view class="sales-p">{{ brief }}</view>-->
      <!--        &lt;!&ndash; 普通商品价格 &ndash;&gt;-->
      <!--        <view v-if="!isGroupProd && defaultSku" class="prod-price">-->
      <!--          <text class="price">￥<text class="price-num">{{ wxs.parsePrice(defaultSku.price)[0] }}</text>.{{ wxs.parsePrice(defaultSku.price)[1] }}</text>-->
      <!--          &lt;!&ndash; <text class="sales"></text> &ndash;&gt;-->
      <!--        </view>-->
      <!--        &lt;!&ndash; 拼团商品价格 &ndash;&gt;-->
      <!--        <view v-if="isGroupProd && defaultGroupSku.actPrice" class="goods-price">-->
      <!--          <view class="current-price">-->
      <!--            <text class="price">￥<text class="price-num">{{ wxs.parsePrice(defaultGroupSku.actPrice)[0] }}</text>.{{ wxs.parsePrice(defaultGroupSku.actPrice)[1] }}</text>-->
      <!--            &lt;!&ndash; <text class="current-price"><text class="sub">￥{{defaultGroupSku.actPrice}}</text></text> &ndash;&gt;-->
      <!--            <text class="condition">{{ groupActivity.groupNumber }}{{ i18n.groupPrice }}</text>-->
      <!--          </view>-->
      <!--          <view class="original">{{ i18n.originalPrice }}<text class="original-price">￥{{ wxs.parsePrice(defaultGroupSku.price)[0] }}.{{ wxs.parsePrice(defaultGroupSku.price)[1] }}</text>-->
      <!--          </view>-->
      <!--        </view>-->
      <!--      </view>-->
      <view class="box_3 flex-col">
        <view class="text-wrapper_2  flex-row">
          <text class="text_2 prod-tit " style="text-align: left">{{ prodName }}</text>
          <!--
          <view class="collection-items">
            <view style="height: 100%;width: 100%;" @tap="addOrCannelCollection">
              <image v-if="!isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col.png" />
              <image v-if="isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col-red.png" />
            </view>
          </view>
           -->
        </view>
        <view class="group_1 flex-row">
          <view class="group_1_view">
            <view class="text-wrapper_3">
              <text class="text_3">￥</text>
              <text class="text_4">{{
                wxs.parsePrice(defaultSku.price)[0]
              }}.
              </text>
              <text class="text_3">{{ wxs.parsePrice(defaultSku.price)[1] }}</text>
            </view>
            <view class="text-wrapper_4">
              <text class="text_5">市场价</text>
              <text class="text_6">￥{{wxs.parsePrice(defaultSku.oriPrice)[0] }}.{{ wxs.parsePrice(defaultSku.oriPrice)[1] }}</text>
              <text class="text_5" style="float: right;">已售 {{defaultSku.stocks}}</text>
            </view>
            <!--            <text class="text_7">已售 {{defaultSku.stocks}}</text>-->
          </view>

        </view>
      </view>
      <!-- 商品信息end -->

      <!-- 预售信息 -->
      <view v-if="preSellStatus" class="sendway">
        <view class="coupon-tit">{{ i18n.preSale }}</view>
        <view class="coupon-con">
          <view class="sendway-item pre-sale-info">
            {{ i18n.expect }} {{ preSellTime }}
          </view>
          <text class="sendway-item pre-sale-info">{{ i18n.startDelivery }}</text>
        </view>
      </view>
      <!-- 预售信息 end -->

      <!-- 配送方式 -->
      <!--      <view v-if="deliveryModeVO" class="sendway">-->
      <!--        <view class="coupon-tit">{{ i18n.delivery }}</view>-->
      <!--        <view class="coupon-con">-->
      <!--          <view v-if="deliveryModeVO.hasShopDelivery" class="sendway-item">-->
      <!--            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/allow.png" />{{ i18n.expressDelivery }}-->
      <!--          </view>-->
      <!--          <view v-if="deliveryModeVO.hasCityDelivery" class="sendway-item">-->
      <!--            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/allow.png" />{{ i18n.sameDelivery }}-->
      <!--          </view>-->
      <!--          <view v-if="deliveryModeVO.hasUserPickUp" class="sendway-item">-->
      <!--            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/allow.png" />{{ i18n.pickStore }}-->
      <!--          </view>-->
      <!--        </view>-->
      <!--      </view>-->
      <!-- 配送方式end -->

      <!-- 满减折 -->
      <view v-if="prodDiscountList.length && preSellStatus!=1" class="discount" @tap="clickDiscount">
        <view class="coupon-tit">{{ i18n.promotion }}</view>
        <view class="coupon-con discount-con">
          <block v-for="(item, index) in prodDiscountList" :key="index">
            <block v-if="index < 1">
              <view class="discount-item">
                <view class="discount-tag">{{ wxs.parseDiscount(item.discountRule, curLang) }}</view>
                <text class="discount-content">
                  <text v-if="item.discountType">{{ i18n.every }}</text>
                  {{ item.discountName }}，{{ i18n.maximumDiscount }}{{ item.maxReduceAmount }}{{ i18n.yuan }}
                </text>
              </view>
            </block>
          </block>
        </view>
        <!-- <view class="num">共{{prodDiscountList.length}}张</view> -->
        <view class="more">...</view>
      </view>
      <!-- 满减折end -->

      <!-- 领券 -->
      <view v-if="couponList.length && !groupActivityId" class="coupon" @tap="showPopup">
        <view class="coupon-tit">{{ i18n.coupons }}</view>
        <view :class="['coupon-con',curLang=='en'?'coupon-con-en':'']">
          <block v-for="(item, index) in couponList" :key="item.couponId">
            <view v-if="index<2" class="item">
              <block v-if="item.couponType == 1">
                {{ wxs.parseDiscountProd(item.couponType, item.cashCondition, item.reduceAmount, curLang) }}
              </block>
              <block v-if="item.couponType == 2">
                {{ wxs.parseDiscountProd(item.couponType, item.cashCondition, item.couponDiscount, curLang) }}
              </block>
            </view>
          </block>
        </view>
        <view class="num">{{ i18n.inTotal }} {{ couponList.length }} {{ i18n.piecesZ }}</view>
        <view class="more">...</view>
      </view>
      <!-- 领券end -->

      <!-- 拼团信息 -->
      <view v-if="joinGroupList.length" class="spell-infor">
        <view class="spell-infor-title">{{ i18n.joinAGroup }}</view>
        <view v-for="(item, groupTeamId) in joinGroupList" :key="groupTeamId" class="spell-infor-content">
          <!-- 头像 -->
          <view class="head-img">
            <image :src="item.sharePic ? item.sharePic : 'https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/head01.png'" />
          </view>
          <!-- 信息 -->
          <view class="spell-msg">
            <view class="username">{{ item.shareNickName }}</view>
            <view class="spell-text">{{ i18n.lack + ' ' }}
              <text class="red-font">{{ item.groupNumber - item.joinNum }}</text>
              {{ ' ' + i18n.lack1 }}
              {{ item.endOfGroupTime.hou }}{{ i18n.time }}{{ item.endOfGroupTime.min }}{{
                i18n.minute
              }}{{ item.endOfGroupTime.sec }}{{ i18n.second }}
            </view>
          </view>
          <!-- 凑团按钮 -->
          <view class="join-group" :data-groupteamid="item.groupTeamId" @tap="toSpellGroupDetail">{{
              i18n.toGatherGroup
            }}
          </view>
        </view>
        <!-- 详情 -->
        <view class="rules clearfix">
          <text class="rules-text01">{{ i18n.groupInvitation + ' ' }}{{
              groupActivity.groupNumber
            }}{{ ' ' + i18n.groupInvitationTips }}
          </text>
          <!-- <text class="rules-text02">玩法详情</text>
      <view class="right-arrow"><image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/more.png"></image></view> -->
        </view>
      </view>
      <!-- 拼团信息end -->
      <!-- 已选规格 -->
      <prod-sku-select v-if="((prodType === 0 && !groupActivityId) || (prodType === 0 && groupInfoLoaded && groupActivityId)) && skuLoad" :pic="pic" :sku-list="skuList" :default-price="price" :sku-show-type="skuShowType" :prod-type="prodType" :pre-sell-status="preSellStatus" :prod-num="prodNum" :has-max-num="hasMaxNum" :max-num="maxNum" :group-activity="groupActivity" :page-type="1" :sku-show="skuShow" :deliveryModeVO="deliveryModeVO" @setSku="setSku" @showSku="showSku" @closeSkuPop="closeSkuPop" @addToCart="addToCart" @buyNow="buyNow" @groupConfirmOrder="groupConfirmOrder" @setProdNum="setProdNum" />
      <!-- 已选规格 end -->
      <!-- 评价 -->
      <!--      <view class="cmt-wrap box-radius">-->

      <!-- 评价 -->
      <view class="cmt-wrap">
        <view class="cmt-tit" @tap="showComment(-1)">
          <view class="cmt-t">{{ i18n.evaluation}} ({{prodCommData.number}})
            <!--                  <text class="cmt-good">{{ i18n.praise + ' ' }}{{ prodCommData.positiveRating }}%</text>-->
          </view>
          <!--                <view class="cmt-count">{{ i18n.inTotal }} {{ prodCommData.number }} {{ i18n.itemTiao }}<text class="arrow" />-->
          <view class="cmt-count">{{"全部"}}<text class="arrow" style="right:-6rpx; " />
          </view>
        </view>
        <view class="cmt-cont_1">
          <!--                <view class="cmt-tag">-->
          <!--                  <text @tap="showComment(-1)">{{ i18n.all + ' ' }}({{ prodCommData.number }})</text>-->
          <!--                  <text @tap="showComment(0)">{{ i18n.praise + ' ' }}({{ prodCommData.praiseNumber }})</text>-->
          <!--                  <text @tap="showComment(1)">{{ i18n.mediumEvaluation + ' ' }}({{ prodCommData.secondaryNumber }})</text>-->
          <!--                  <text @tap="showComment(2)">{{ i18n.badEvaluation + ' ' }}({{ prodCommData.negativeNumber }})</text>-->
          <!--                  <text class="last-text" @tap="showComment(3)">{{ i18n.havePictures + ' ' }}({{ prodCommData.picNumber }})</text>-->
          <!--                </view>-->
          <view class="cmt-items">
            <view v-for="(item, prodCommId) in littleCommPage" :key="prodCommId" class="cmt-item">
              <view class="cmt-user">
                <!--                      <text class="date">{{ item.recTime }}</text>-->
                <view class="cmt-user-info">
                  <image class="user-img" :src="item.pic?item.pic:'https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/head04.png'" />
                  <view class="nickname">
                    <view class="name-star">
                      <view class="name" style="color: #ADADAD">{{ item.isAnonymous==1?i18n.anonymousEvaluation:item.nickName }}</view>
                      <!--                            <comm-star :value="item.score" />-->
                    </view>
                    <view style="color: #999;">{{ item.skuName || '' }}</view>
                  </view>

                </view>
              </view>
              <view class="cmt-cnt">
                <text decode="true" style="margin-left: 8vw">{{ item.content }}</text>
              </view>
              <scroll-view v-if="item.pics && item.pics.length" class="cmt-attr" scroll-x="true">
                <image v-for="(commPic, index) in item.pics" :key="index" mode="aspectFit" :src="commPic" :data-pics="item.pics" :data-src="commPic" @tap="clickImg" />
              </scroll-view>
            </view>
          </view>
          <view v-if="showBtnAll" class="cmt-more-v">
            <text @tap="showComment(-1)">{{ i18n.viewAllEvaluation }}</text>
          </view>
        </view>
      </view>
      <!-- 评价 end -->

      <!-- 商品详情 -->
      <view class="prod-detail">
        <view class="prod-detail-title">
          <span class="prod-detail-title-text">—— 产品介绍 ——</span>
        </view>
        <rich-text v-if="content" :nodes="content" />
      </view>
      <!-- 商品详情end -->

      <!-- 底部按钮 -->
      <view v-if="!isGroupProd" class="cart-footer">
        <view class="btn icon" @tap="toHomePage">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/home.png" />
          {{ i18n.homepage }}
        </view>
        <view class="btn icon" @tap="handleCustomService">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/service.png" />
          {{ i18n.customerService }}
        </view>
        <!--
        <view class="btn icon" @tap="toCartPage">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/tabbar/basket.png" />
          {{ i18n.shoppingCart }}
          <view v-if="totalCartNum>0" class="badge">{{ totalCartNum > 99 ? '99+' : totalCartNum }}</view>
        </view>
         -->
        <view class="btn icon" @tap="addOrCannelCollection">
          <image v-if="!isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col.png" />
          <image v-if="isCollection" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/prod-col-red.png" />
          收藏
        </view>
        <block v-if="preSellStatus != 1">
          <view class="btn cart btn-items" @tap="addToCart">
            <text>{{ i18n.addShoppingCart }}</text>
          </view>
          <view class="btn buy btn-items " @tap="buyNow">
            <text>{{ i18n.buyNow }}</text>
          </view>
        </block>
        <view v-if="preSellStatus == 1" class="btn pre-sale-buy cart-radius" @tap="buyNow">{{ i18n.buyNow }}</view>
      </view>
      <!--      <view class="box_6 flex-col">-->
      <!--        <view class="group_5 flex-col">-->
      <!--          <view class="box_7 flex-row">-->
      <!--            <view class="image-text_4 flex-col justify-between">-->
      <!--              <image-->
      <!--                  class="thumbnail_6"-->
      <!--                  referrerpolicy="no-referrer"-->
      <!--                  src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/tabbar/homepage.png"-->
      <!--              />-->
      <!--              <view class="text-group_4">-->
      <!--                <text class="text_18">首页</text>-->
      <!--                <text class="text_19"></text>-->
      <!--              </view>-->
      <!--            </view>-->
      <!--            <view class="image-text_5 flex-col justify-between">-->
      <!--              <image-->
      <!--                  class="thumbnail_7"-->
      <!--                  referrerpolicy="no-referrer"-->
      <!--                  src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/shop-customer-service.png"-->
      <!--              />-->
      <!--              <view class="text-group_5">-->
      <!--                <text class="text_20">客服</text>-->
      <!--                <text class="text_21"></text>-->
      <!--              </view>-->
      <!--            </view>-->
      <!--            <view class="image-text_6 flex-col justify-between">-->
      <!--              <image-->
      <!--                  class="thumbnail_8"-->
      <!--                  referrerpolicy="no-referrer"-->
      <!--                  src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/tabbar/basket.png"-->
      <!--              />-->
      <!--              <text class="text-group_6">收藏</text>-->
      <!--            </view>-->
      <!--            <text class="text_22">加入购物车</text>-->
      <!--            <view class="text-wrapper_7 flex-col">-->
      <!--              <text class="text_23">立即购买</text>-->
      <!--            </view>-->
      <!--          </view>-->
      <!--          <view class="box_8 flex-row">-->
      <!--            <view class="block_1 flex-col"></view>-->
      <!--          </view>-->
      <!--        </view>-->
      <!--      </view>-->
      <!-- 底部按钮 end -->

      <!-- 【拼团】底部按钮 -->
      <view v-if="isGroupProd" class="cart-footer">
        <view class="footer">
          <view class="btn icon" @tap="toHomePage">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/home.png" />
            {{ i18n.homepage }}
          </view>
          <view class="btn icon" @tap="handleCustomService">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/service.png" />
            {{ i18n.customerService }}
          </view>
          <view class="btn icon" @tap="toCartPage">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/tabbar/basket.png" />
            {{ i18n.shoppingCart }}
            <view v-if="totalCartNum>0" class="badge">{{ totalCartNum > 99 ? '99+' : totalCartNum }}</view>
          </view>
          <view class="buy-btn alone-buy cart-radius" @tap="showSku(false)">
            <text>{{ i18n.individualShopping }}</text>
          </view>
          <view :class="['buy-btn group-buy cart-radius', groupActivity.activityStatus === 1 ? 'gray-btn' : '']" @tap="showGroupSku">
            <text>{{ i18n.startAGroup }}</text>
          </view>
        </view>
      </view>
      <!-- end 底部按钮 -->

      <!-- 满减折弹窗 -->
      <view v-if="showDiscountPopup" class="popup-hide">
        <view class="popup-box radius">
          <view class="popup-tit radius">
            <text>{{ i18n.promotion }}</text>
            <view class="close" @tap="clickDiscount" />
          </view>
          <view class="popup-cnt popup-discount">
            <view class="coupon-con discount-con">
              <block v-for="(item, discountId) in prodDiscountList" :key="discountId">
                <view class="discount-item">
                  <view class="discount-tag">{{ wxs.parseDiscount(item.discountRule, curLang) }}</view>
                  <text class="discount-content">{{ item.discountName }}，{{
                      i18n.maximumDiscount
                    }}{{ item.maxReduceAmount }}{{ i18n.yuan }}
                  </text>
                </view>
              </block>
            </view>
          </view>
        </view>
      </view>
      <!-- 满减折弹窗 end -->

      <!-- 优惠券 -->
      <view v-if="popupShow" class="popup-hide">
        <view class="popup-box radius">
          <view class="popup-tit radius">
            <text>{{ i18n.coupon }}</text>
            <view class="close" @tap="closePopup" />
          </view>
          <view class="popup-cnt">
            <block v-for="(item, couponId) in couponList" :key="couponId">
              <coupon :show-time-type="1" :can-use="item.canUse" :coupon-item="item" :type="item.type" />
            </block>
          </view>
        </view>
      </view>
      <!-- 优惠券 end -->

      <!-- 直播悬浮按钮 -->
      <!-- #ifdef MP-WEIXIN -->
      <view v-if="liveRoomParams[0].liveStatus === 101 && liveRoomParams.length" class="live" :data-roomid="liveRoomParams[0].roomId" :data-url="liveRoomParams[0].url" @tap="toLivePage">
        <!-- <image class="earn" src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/live-broadcast/living03.png"></image> -->
        <rhythm-beat />
        <view class="live-txt">{{ i18n.inLive }}</view>
      </view>
      <!-- #endif -->

      <!-- 悬浮按钮 -->
      <view :class="'suspension-box ' + (showBacktop?'scroll-top':'')">
        <!-- 赚字浮层 -->
        <view v-if="isDist && isDistProd" class="promo-con" @tap="onShowShare">
          <view class="earn">{{ i18n.earn }}</view>
        </view>

        <!-- 分享 -->
        <!-- #ifdef MP-WEIXIN -->
        <button v-if="!(isDist && isDistProd)" class="suspension-btn btn-type" open-type="share">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/share-prod.png" />
        </button>
        <!-- #endif -->

        <!-- 回到顶部 -->
        <view v-if="showBacktop" class="suspension-btn" @tap="backToTop">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/back-to-top.png" />
        </view>
      </view>
      <!-- /悬浮按钮 -->

      <!-- 分享弹窗 -->
      <view v-if="shareShow" class="promo-share">
        <view class="promo-main">
          <view class="promo-icons-close" @tap="closeEarn">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/close.png" />
          </view>
          <view class="promo-tit">
            <text>{{ i18n.shareFriendsNow }}</text>
          </view>
          <view class="promo-desc">
            <text>{{ i18n.shareFriendsTips1 }}</text>
          </view>
          <view class="promo-icons">
            <button v-if="isWechat" class="promo-img1" open-type="share" @tap="onShareWay">
              <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/weixin.png" />
              {{ i18n.weChat }}
            </button>
            <view class="promo-img1" @tap="genWeixinCode">
              <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/erweima.png" />
              {{ i18n.QRCode }}
            </view>
          </view>
          <view class="promo-btn" @tap="toDistCenterPage">{{ i18n.myDistributorCenter }}</view>
        </view>
      </view>
      <!-- 分享弹窗 end -->

      <!-- 二维码弹窗 -->
      <view v-if="wxCodeShow" class="code-popup">
        <view class="code-main">
          <view class="close-v" @tap.stop="closeCodePopup">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/close.png" class="close-png" />
          </view>
          <view class="code-v">
            <image :src="shareWxCode" class="wx-code" />
          </view>
          <!-- #ifndef H5-->
          <view class="code-txt" @tap="downloadImg">{{ i18n.saveAlbum }}</view>
          <!-- #endif -->
        </view>
      </view>
      <!-- 二维码弹窗 end -->

      <!-- 引导分享蒙版 -->
      <view v-if="guideShare" class="guide-share-mask">
        <view class="mask" />
        <view class="guide-share-close" @tap="guideShare=false">
          <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/close.png" mode="" />
        </view>
        <view class="guide-content">
          <view class="share-img">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/shareIcon.png" />
          </view>
          <view class="share-word">
            <view class="big-word">{{ i18n.shareFriendsNow }}</view>
            <view class="small-word">{{ i18n.shareFriendsTips2 }}</view>
          </view>
        </view>
      </view>
      <!-- 引导分享蒙版 end -->
    </view>
    <!-- 商品详情end -->
    <!-- 评价弹窗 -->
    <view v-if="commentShow" :class="prodCommData.number?'cmt-popup':'cmt-no-popup'">
      <view class="cmt-tit">
        <view class="cmt-t">{{ i18n.productEvaluation }}
          <text class="cmt-good">{{ i18n.rating + ' ' }}{{ prodCommData.positiveRating }}%</text>
        </view>
        <view class="close" @tap="closePopup" />
      </view>
      <scroll-view scroll-y="true" class="cmt-cont_">
        <!--        <view class="cmt-tag menu-list">-->
        <view class="cmt-tag menu-list">
          <!--          <text data-evaluate="-1" :class="evaluate==-1?'selected':''" @tap="getProdCommPage">{{-->
          <!--              i18n.all + ' '-->
          <!--            }}({{ prodCommData.number }})-->
          <!--          </text>-->
          <!--          <text data-evaluate="0" :class="evaluate==0?'selected':''" @tap="getProdCommPage">{{-->
          <!--              i18n.praise + ' '-->
          <!--            }}({{ prodCommData.praiseNumber }})-->
          <!--          </text>-->
          <!--          <text data-evaluate="1" :class="evaluate==1?'selected':''" @tap="getProdCommPage">-->
          <!--            {{ i18n.mediumEvaluation + ' ' }}({{ prodCommData.secondaryNumber }})-->
          <!--          </text>-->
          <!--          <text data-evaluate="2" :class="evaluate==2?'selected':''" @tap="getProdCommPage">{{-->
          <!--              i18n.badEvaluation + ' '-->
          <!--            }}({{ prodCommData.negativeNumber }})-->
          <!--          </text>-->
          <!--          <text data-evaluate="3" :class="evaluate==3?'selected':''" @tap="getProdCommPage">{{-->
          <!--              i18n.havePictures + ' '-->
          <!--            }}({{ prodCommData.picNumber }})-->
          <!--          </text>-->
          <view class="menu-item">
            <text :data-evaluate="-1" :class="evaluate == -1 ? 'selected' : '' " @tap="getProdCommPage">{{i18n.all + ' '}}({{prodCommData.number}})</text>
            <view class="bottom-block" v-if="evaluate == -1"></view>
          </view>
          <view class="menu-item">
            <text :data-evaluate="0" :class="evaluate==0?'selected':''" @tap="getProdCommPage">{{i18n.praise + ' '}}({{prodCommData.praiseNumber}})</text>
            <view class="bottom-block" v-if="evaluate == 0"></view>
          </view>
          <view class="menu-item">
            <text :data-evaluate="1" :class="evaluate==1?'selected':''" @tap="getProdCommPage">{{i18n.mediumEvaluation + ' '}}({{prodCommData.secondaryNumber}})</text>
            <view class="bottom-block" v-if="evaluate == 1"></view>
          </view>
          <view class="menu-item">
            <text :data-evaluate="2" :class="evaluate==2?'selected':''" @tap="getProdCommPage">{{i18n.badEvaluation + ' '}}({{prodCommData.negativeNumber}})</text>
            <view class="bottom-block" v-if="evaluate == 2"></view>
          </view>
          <view class="menu-item">
            <text :data-evaluate="3" :class="evaluate==3?'selected':''" @tap="getProdCommPage">{{i18n.havePictures + ' '}}({{prodCommData.picNumber}})</text>
            <view class="bottom-block" v-if="evaluate == 3"></view>
          </view>
        </view>
        <view class="cmt-items">
          <view v-for="(item, prodCommId) in prodCommPage.records" :key="prodCommId" class="cmt-item">
            <!--            <view class="cmt-user">-->
            <!--              <text class="date">{{ item.recTime }}</text>-->
            <!--              <view class="cmt-user-info">-->
            <!--                <image class="user-img" :src="item.pic?item.pic:'https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/head04.png'"/>-->
            <!--                <view class="nickname">-->
            <!--                  <view class="name-star">-->
            <!--                    <view class="name">{{ item.isAnonymous == 1 ? i18n.anonymousEvaluation : item.nickName }}</view>-->
            <!--                    <comm-star :value="item.score"/>-->
            <!--                  </view>-->
            <!--                  <view style="color: #999;">{{ item.skuName || '' }}</view>-->
            <!--                </view>-->
            <!--              </view>-->
            <!--            </view>-->
            <!--            <view class="cmt-cnt records-margin">-->
            <!--              <comm-star :value="item.score"/>-->
            <!--              <text decode="true">{{ item.content }}</text>-->
            <!--            </view>-->
            <!--            <scroll-view v-if="item.pics && item.pics.length" class="cmt-attr" scroll-x="true">-->
            <!--              <image-->
            <!--                  v-for="(commPic, index) in item.pics"-->
            <!--                  :key="index"-->
            <!--                  :src="commPic"-->
            <!--                  :data-pics="item.pics"-->
            <!--                  :data-src="commPic"-->
            <!--                  @tap="clickImg"-->
            <!--              />-->
            <!--            </scroll-view>-->
            <!--            <view v-if="item.replyContent" class="cmt-reply">-->
            <!--              <text class="reply-tit">{{ i18n.shopReply }}：</text>-->
            <!--              <text class="reply-content">{{ item.replyContent }}</text>-->
            <!--            </view>-->
            <view class="recordsListItem">
              <view class="recordsListItem-head">
                <view class="avatar">
                  <image class="user-img" :src="item.pic?item.pic:'https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/head04.png'" />
                </view>
                <view class="info">
                  <view class="content">
                    <view class="name">{{ item.isAnonymous == 1 ? i18n.anonymousEvaluation : item.nickName }}</view>
                    <comm-star :value="item.score" />
                  </view>
                  <view class="time">
                    <text class="date">{{ item.recTime }}</text>
                  </view>
                </view>
              </view>
              <view class="recordsListItem-body">
                <view>
                  <!--                  <text class="buy">{{ "已购 实案说法电子书+U盘+语音包"}}</text>-->
                  <text class="buy">{{"已购"}}</text>
                </view>
                <view class="content">
                  <text decode="true">{{ item.content }}</text>
                </view>
              </view>
            </view>
          </view>
        </view>
        <!-- 列表空 -->
        <view v-if="!prodCommPage.records.length" class="empty">
          <view class="empty-icon">
            <image src="https://mall-1312577323.cos.ap-chengdu.myqcloud.com/mall/images/icon/empty-com.png" />
          </view>
          <view class="empty-text">{{ i18n.noProductReviewsTips }}</view>
        </view>
        <!-- /列表空 -->
        <view v-if="prodCommPage.pages > prodCommPage.current" class="load-more">
          <text @tap="getMoreCommPage">{{ i18n.clickLoadMore }}</text>
        </view>
      </scroll-view>
    </view>
    <!-- 评价弹窗 end -->
  </view>
</template>

<script module="wxs" lang="wxs" src="../../wxs/number.wxs">
</script>

<script>
// pages/prod/prod.js
const app = getApp().globalData;
var http = require("../../utils/http.js");
var config = require("../../utils/config.js");
var util = require("../../utils/util.js");
var Qr = require("../../utils/wxqrcode.js");
import coupon from "../../components/coupon/index.vue";
import commStar from "../../components/comm-star/index.vue";
import Wechat from "../../utils/wechat.js";
import rhythmBeat from "../../components/rhythm-beat/index.vue";
import prodSkuSelect from '@/components/prod-sku-select/index.vue';

export default {
  data () {
    return {
      isWechat: false, //是否为微信环境
      shopId: 1,
      picDomain: config.picDomain,
      indicatorDots: true,
      indicatorColor: '#f2f2f2',
      indicatorActiveColor: '#e43130',
      isAuthInfo: true,
      autoplay: true,
      interval: 3000,
      duration: 1000,
      prodNum: 1,
      totalCartNum: 0,
      groupActivityId: 0, //团购活动ID
      isGroupProd: false, //是否有效团购商品
      pic: "",
      imgs: '',
      prodName: '',
      price: 0,
      actPrice: 0,
      content: '',
      prodId: 0,
      brief: '',
      skuId: 0,
      popupShow: false,
      // 是否获取过用户领取过的优惠券id
      loadCouponIds: false,
      skuShow: false,
      skuGroupShow: false,
      commentShow: false,
      couponList: [],

      skuList: [],
      skuGroup: {},
      findSku: true,
      defaultSku: {},
      defaultGroupSku: {},

      prodCommData: {},
      prodCommPage: {
        current: 0,
        pages: 0,
        records: []
      },
      littleCommPage: [],
      evaluate: -1,
      isCollection: false,
      shareShow: false,
      isDist: false, //是否分销员
      isDistProd: false, //是否分销商品
      distributionCardNo: "", //分销员卡号
      wxCodeShow: false, //是否显示二维码弹层
      shareWxCode: "", //分享二维码图片路径
      groupActivity: {}, // 团购活动
      endOfGroupTime: {}, // 距离团购活动结束还剩多久
      joinGroupList: [], // 可加入的团列表
      skuShowType: 0, // sku的显示类型 0普通sku 1拼团sku
      joinGroupListTimeOut: null,
      groupActivityTimeOut: null,
      showBacktop: false, //回到顶部显隐
      prodDiscountList: [], // 商品促销活动列表
      videoContext: '', // 视频组件
      isPlaying: false, // 视频是否播放中
      currentSwiper: 0, // 当前轮播index
      touchS: [0, 0], // 滑动屏幕开始坐标
      touchE: [0, 0], // 滑动屏幕结束坐标
      showDiscountPopup: false, //促销弹窗显隐
      video: "",
      videoDuration: "",
      scrollTop: -1, //

      guideShare: false, // 引导蒙版

      deliveryModeVO: null, // 配送方式

      // 预售
      preSellStatus: 0, // 预售状态 1：开启 0：未开启
      preSellTime: '', // 预售发货时间

      liveRoomParams: [], // 直播列表
      hasMaxNum: false, // 是否限购
      maxNum: 0, // 限购数量
      scene: '',
      curLang: uni.getStorageSync('lang'),
      showBtnAll: false,
      prodType: 0,
      skuLoad: false,
      groupInfoLoaded: false
    };
  },

  components: {
    coupon,
    commStar,
    rhythmBeat,
    prodSkuSelect
  },
  props: {},

  computed: {
    i18n () {
      return this.$t('index')
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // #ifdef H5
    this.isWechat = Wechat.isWechat()
    // #endif
    // #ifdef MP-WEIXIN
    this.isWechat = true
    // #endif

    this.setData({
      prodId: this.$Route.query.prodid,
      distributionCardNo: this.$Route.query.cardno || '',
    })
    // 普通的跳转
    if (this.$Route.query.prodid) {
      this.executionFunction()
    }
    // 扫码进入 (小程序)
    if (this.$Route.query.scene) {
      let scene = decodeURIComponent(this.$Route.query.scene)
      // 如果是微信小程序中下载保存的二维码
      if (scene.indexOf(',') !== -1) {
        this.setData({
          prodId: scene.split(',')[0],
          distributionCardNo: scene.split(',')[1]
        });
        this.executionFunction()
        this.saveShareLog()
      } else {
        this.setData({
          scene: scene
        });
        //根据Ticket获取保存的内容
        this.getContent();
      }
    }
    if (this.$Route.query.cardno || this.$Route.query.isShare) {
      this.saveShareLog()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo');
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    uni.setNavigationBarTitle({
      title: this.i18n.commodityDetails
    });
    // 加载购物车数字
    this.getCartCount()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    // this.closePopup()
    this.skuShow = false
    if (this.isPlaying) {
      this.stopPlay()
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearTimeout(this.joinGroupListTimeOut);
    clearTimeout(this.groupActivityTimeOut);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  },

  /**
   * 用户点击转发
   */
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      var cardno = wx.getStorageSync("distCardNo");
      return {
        title: this.prodName,
        path: '/pages/prod/prod?prodid=' + this.prodId + '&cardno=' + cardno + '&isShare=1',
        imageUrl: this.pic
      };
    } else {
      return {
        title: this.prodName,
        path: '/pages/prod/prod?prodid=' + this.prodId + '&isShare=1',
        imageUrl: this.pic
      };
    }
  },
  methods: {
    /**
     * 隐藏sku弹窗
     */
    closeSkuPop () {
      this.closePopup()
    },

    /**
     * 修改商品的sku
     */
    setSku (sku, findSku) {
      this.findSku = findSku
      // 团购的sku
      if (sku.groupSkuId) {
        this.defaultGroupSku = sku
      }
      this.defaultSku = sku
    },

    /**
     * 修改商品数量
     */
    setProdNum (prodNum) {
      this.prodNum = prodNum
    },

    /**
     * 获取购物车
     */
    getCartCount () {
      var params = {
        url: '/p/shopCart/prodCount',
        method: "GET",
        dontTrunLogin: true,
        callBack: res => {
          this.totalCartNum = res
        }
      }
      http.request(params)
    },

    /**
     * 咨询客服
     */
    handleCustomService () {
      util.checkAuthInfo(() => {
        uni.navigateTo({
          url: '/pages/chat/chat?shopid=' + 0 + '&prodid=' + this.prodId
        });
      })
    },

    /**
     * 执行函数
     */
    executionFunction: function () {
      // 加载商品信息
      this.getProdInfo();
      // 加载评论数据
      this.getProdCommData();
      // 加载评论项
      this.getLittleProdComm();
      // 查看用户是否关注
      this.getCollection();
      //查询用户 是否为分销员
      this.getDistInfo();
    },

    /**
     * 根据Ticket获取保存的内容
     */
    getContent: function () {
      http.request({
        url: "/qrcodeTicket/getContent",
        method: "GET",
        data: {
          ticket: this.scene
        },
        callBack: (res) => {
          var content = JSON.parse(res.content);
          var ids = JSON.parse(content.content)
          if (res.type == 1) { //pc团购二维码跳转
            this.setData({
              prodId: ids.prodId,
              groupActivityId: ids.groupActivityId
            })
          } else if (res.type == 2) { //分销员二维码跳转
            this.setData({
              prodId: ids.shareProdId,
              distributionCardNo: ids.cardNo
            })
          }
          this.executionFunction() //所有需要加载的函数
          this.saveShareLog()
        }
      })
    },

    /**
     * 分销绑定用户
     */
    bindDistUser (cardno) {
      http.request({
        url: "/p/distribution/bindUser",
        method: "post",
        data: cardno
      });
    },

    /**
     * 查询分销相关信息
     */
    getDistInfo () {
      //查询分销开关是否开启
      http.request({
        url: "/p/distribution/distributionBasicSet/canDistribution",
        method: "GET",
        dontTrunLogin: true,
        data: {
          shopId: 1
        },
        callBack: res => {
          if (res == 1) {
            this.getIsDistInfo();
          }
        }
      });
    },

    /**
     * 查询用户 是否为分销员
     */
    getIsDistInfo () {
      http.request({
        url: "/p/distribution/user/distributionUserInfo",
        method: "GET",
        data: {
          shopId: 1
        },
        callBack: res => {
          if (res && res.state == 1) {
            this.setData({
              isDist: true
            });
            this.getIsDistProd();
            wx.setStorageSync("distCardNo", res.cardNo);
          }
        }
      });
    },

    /**
     * 查询是否为分销商品
     */
    getIsDistProd () {
      http.request({
        url: "/p/distribution/prod/isDistributionProd",
        method: "GET",
        data: {
          prodId: this.prodId
        },
        callBack: res => {
          if (res) {
            this.setData({
              isDistProd: true
            });
          }
        }
      });
    },

    /**
     * 获取是否关注信息
     */
    getCollection () {
      var params = {
        url: "/p/user/collection/isCollection",
        method: "GET",
        dontTrunLogin: true,
        data: {
          prodId: this.prodId
        },
        callBack: res => {
          this.setData({
            isCollection: res
          });
        }
      };
      http.request(params);
    },

    /**
     * 添加或者取消收藏商品
     */
    addOrCannelCollection () {
      util.checkAuthInfo(() => {
        util.tapLog(3)
        var params = {
          url: "/p/user/collection/addOrCancel",
          method: "POST",
          data: this.prodId,
          callBack: res => {
            this.setData({
              isCollection: !this.isCollection
            });
            uni.showToast({
              title: this.isCollection ? this.i18n.collectionAdded : this.i18n.collectionCancelled,
              icon: 'none'
            })
          }
        };
        http.request(params);
      })
    },

    // 保存浏览记录
    prodBrowseLog () {
      http.request({
        url: "/p/prodBrowseLog",
        method: "POST",
        data: {
          prodId: this.prodId
        },
        callBack: res => {
        }
      });
    },

    // 获取商品信息
    getProdInfo () {
      var params = {
        url: "/prod/prodInfo",
        method: "GET",
        data: {
          prodId: this.prodId // userType: 0
        },
        callBack: res => {
          this.prodInfo = res
          var imgs = res.imgs ? res.imgs.split(",") : []
          var content = util.formatHtml(res.content);
          this.setData({
            imgs: imgs,
            content: content,
            price: res.price,
            prodName: res.prodName,
            groupActivityId: res.groupActivityId,
            prodId: res.prodId,
            brief: res.brief,
            // skuId: res.skuId
            skuList: res.skuList,
            pic: res.pic,
            video: res.video ? res.video : '',
            deliveryModeVO: res.deliveryModeVO, // 配送方式
            preSellStatus: res.preSellStatus, // 预售状态 1：开启 0：未开启
            preSellTime: res.preSellTime, //预售发货时间
            liveRoomParams: res.liveRoomParams, // 直播列表
            prodType: res.prodType,
            skuLoad: true
          });
          // 初始化视频
          if (res.video) {
            this.$nextTick(() => {
              this.videoContext = uni.createVideoContext('myVideo', this)
            })
          }
          // 团购活动
          if (res.groupActivityId) {
            this.getGroupActivity();
          } //促销活动

          this.getPordDiscountList(); // 获取优惠券
          if (uni.getStorageSync('token')) {
            this.prodBrowseLog()
          }

          this.getCouponList()
        },
        errCallBack: err => {
          if (err.code === 'A00001') {
            uni.showModal({
              title: this.i18n.tips,
              content: err.msg,
              showCancel: false,
              cancelText: this.i18n.cancel,
              confirmText: this.i18n.confirm,
              success: (res) => {
                if (res.confirm) {
                  getCurrentPages().length > 1 ? uni.navigateBack() : uni.switchTab({ url: '/pages/index/index' })
                }
              }
            })
          }
        }
      };
      http.request(params);
    },

    getProdCommData () {
      http.request({
        url: "/prod/prodCommData",
        method: "GET",
        data: {
          prodId: this.prodId
        },
        callBack: res => {

          this.setData({
            prodCommData: res,
            showBtnAll: res.number > 2 ? true : false
          });
        }
      });
    },

    // 获取部分评论
    getLittleProdComm () {
      if (this.prodCommPage.records.length) {
        return;
      }

      this.getProdCommPage();
    },

    getMoreCommPage (e) {
      this.getProdCommPage();
    },

    // 获取分页获取评论
    getProdCommPage (e) {
      util.tapLog(3)
      if (e) {
        console.log(e)
        if (e.currentTarget.dataset.evaluate === this.evaluate) {
          return;
        }

        this.setData({
          prodCommPage: {
            current: 0,
            pages: 0,
            records: []
          },
          evaluate: e.currentTarget.dataset.evaluate
        });
      }

      http.request({
        url: "/prod/prodCommPageByProd",
        method: "GET",
        data: {
          prodId: this.prodId,
          size: 10,
          current: this.prodCommPage.current + 1,
          evaluate: this.evaluate
        },
        callBack: res => {
          res.records.forEach(item => {
            if (item.pics) {
              item.pics = item.pics.split(',');
            }
          });
          let records = this.prodCommPage.records;
          records = records.concat(res.records);
          this.setData({
            prodCommPage: {
              current: res.current,
              pages: res.pages,
              records: records
            }
          }); // 如果商品详情中没有评论的数据，截取两条到商品详情页商品详情

          if (!this.littleCommPage.length) {
            this.setData({
              littleCommPage: records.slice(0, 2)
            });
          }
        }
      });
    },

    /**
     * 评论小图点击事件(点击图片显示大图)
     */
    clickImg: function (e) {
      const current = e.currentTarget.dataset.src //获取当前点击的 图片 url
      var pics = e.currentTarget.dataset.pics
      uni.previewImage({
        current: current,
        urls: pics
      })
    },

    /**
     * 优惠券列表
     */
    getCouponList () {
      http.request({
        url: "/coupon/listByProdId",
        method: "GET",
        data: {
          prodId: this.prodId,
          shopId: this.shopId
        },
        callBack: res => {
          this.setData({
            couponList: res
          });
        }
      });
    },

    getGroupActivity () {
      http.request({
        url: "/groupProd/info",
        method: "GET",
        data: {
          prodId: this.prodId,
          groupActivityId: this.groupActivityId
        },
        callBack: res => {
          // if (res.success) {
          this.setData({
            groupActivity: res,
            isGroupProd: true,
            maxNum: res.maxNum,
            hasMaxNum: res.hasMaxNum
          });
          this.groupActivityCountdown(res);
          if (res.hasGroupTip) {
            this.getJoinGroupList();
          }
          // } else {
          // 	this.setData({
          //     groupActivityId: null
          //   });
          // }
          this.$forceUpdate()
          this.groupInfoLoaded = true
        },
        errCallBack: err => {
          if (err.code === 'A00001') {
            this.setData({
              groupActivityId: ''
            })
          }
        }
      });
    },

    // 团购倒计时
    groupActivityCountdown (groupActivity) {
      let endOfGroupTime; // activityStatus 1 未开始

      if (groupActivity.activityStatus === 1) {
        endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(groupActivity.startTime));
      } else {
        endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(groupActivity.endTime));
      }
      if (this.endOfGroupTime.signs == 0) {
        clearTimeout(this.joinGroupListTimer);
        clearTimeout(this.endOfGroupTimer);
        // 拼团结束，刷新当前页面
        setTimeout(() => {
          uni.redirectTo({
            url: '/pages/prod/prod?prodid=' + this.prodId
          })
        }, 100)
        // uni.redirectTo({
        // 	url: '/pages/prod/prod?prodid=' + this.prodId
        // })
        return
      }
      this.setData({
        endOfGroupTime: endOfGroupTime,
        groupActivityTimeOut: setTimeout(() => this.groupActivityCountdown(groupActivity), 1000)
      });
    },

    // 可加入的拼团列表
    getJoinGroupList () {
      http.request({
        url: "/groupProd/joinGroupList",
        method: "GET",
        data: {
          prodId: this.prodId,
          groupActivityId: this.groupActivityId,
          showSize: 3
        },
        callBack: res => {
          this.setData({
            joinGroupList: res
          });

          if (res && res.length) {
            this.joinGroupListCountdown(res);
          }
        }
      });
    },

    joinGroupListCountdown (joinGroupList) {
      joinGroupList.forEach(item => {
        item.endOfGroupTime = util.endOfStartTime(new Date().getTime(), util.dateToTimestamp(item.endTime));
        if (!item.endOfGroupTime.signs) {
          uni.redirectTo({
            url: '/pages/prod/prod?prodid=' + this.prodId
          })
        }
      });
      this.setData({
        joinGroupList: joinGroupList,
        joinGroupListTimeOut: setTimeout(() => this.joinGroupListCountdown(joinGroupList), 1000)
      });
    },

    /**
     * 去凑团
     */
    toSpellGroupDetail (e) {
      util.tapLog(3)
      const groupTeamId = e.currentTarget.dataset.groupteamid;
      util.checkAuthInfo(() => {
        uni.navigateTo({
          url: '/package-activities/pages/spell-group-details/spell-group-details?groupTeamId=' + groupTeamId
        });
      });
    },

    /**
     * 跳转到首页
     */
    toHomePage: function () {
      util.tapLog(3)
      // wx.switchTab({
      // 	url: '/pages/index/index'
      // });
      this.$Router.pushTab('/pages/index/index')
    },

    /**
     * 跳转到购物车
     */
    toCartPage: function () {
      util.tapLog(3)
      // wx.switchTab({
      // 	url: '/pages/basket/basket'
      // });
      this.$Router.pushTab('/pages/basket/basket')
    },

    /**
     * 加入购物车
     */
    addToCart: function (event) {

      if (this.isPlaying) {
        this.stopPlay()
      }
      if (!this.skuShow) {
        this.skuShow = true
        return
      }
      if (!this.findSku) {
        return;
      }
      if (this.prodNum == 0 || this.prodNum == '') {
        uni.showToast({
          title: this.i18n.inputCorrectQuantity,
          icon: 'none',
          duration: 1000
        })
        this.prodNum = 1;
        return
      }

      var ths = this; // 查看是否授权

      util.checkAuthInfo(() => {
        ths.callChangeItem();
      });
    },

    callChangeItem () {
      http.request({
        url: "/p/shopCart/changeItem",
        method: "POST",
        data: {
          basketId: 0,
          count: this.prodNum,
          prodId: this.prodId,
          shopId: this.shopId,
          skuId: this.defaultSku.skuId,
          distributionCardNo: this.distributionCardNo
        },
        callBack: res => {
          util.tapLog(4, null, null, this.prodNum)
          let num = this.totalCartNum + Number(this.prodNum)
          this.setData({
            totalCartNum: num,
            skuShow: false
          });
          uni.showToast({
            title: this.i18n.successfullyAddedCart,
            icon: "none"
          });
        }
      });
    },

    /**
     * 立即购买
     */
    buyNow: function () {
      if (this.isPlaying) {
        this.stopPlay()
      }
      if (!this.skuShow) {
        this.skuShow = true
        return
      }
      if (!this.findSku) {
        return;
      }
      if (this.prodNum == 0 || this.prodNum == '') {
        uni.showToast({
          title: this.i18n.inputCorrectQuantity,
          icon: 'none',
          duration: 1000
        })
        this.prodNum = 1;
        return
      }
      if (this.prodNum > this.defaultSku.stocks) {
        uni.showToast({
          title: this.i18n.insufficientStock,
          icon: 'none',
          duration: 1000,
          mask: true
        });
        return;
      }
      var ths = this;
      // 查看是否授权
      util.checkAuthInfo(() => {
        util.tapLog(3)
        wx.setStorageSync("orderItem", JSON.stringify({
          prodId: ths.prodId,
          skuId: ths.defaultSku.skuId,
          prodCount: ths.prodNum,
          shopId: ths.shopId,
          distributionCardNo: ths.distributionCardNo
        }));
        uni.navigateTo({
          url: '/pages/submit-order/submit-order?orderEntry=1'
        });
      });
    },

    /**
     * 减数量
     */
    onCountMinus: function () {
      var prodNum = this.prodNum;
      if (prodNum > 1) {
        this.setData({
          prodNum: prodNum - 1
        });
      }
    },

    /**
     * 加数量
     */
    onCountPlus: function () {
      util.tapLog(3)
      var prodNum = parseInt(this.prodNum); // 取整数
      // 判断是否限购: 开团则限制购买数量；单独购买不作限制
      if (this.hasMaxNum && this.skuShowType) {
        if (prodNum < this.defaultSku.stocks && prodNum < this.maxNum) {
          this.setData({
            prodNum: prodNum + 1
          });
        } else if (prodNum >= this.defaultSku.stocks && this.defaultSku.stocks < this.maxNum) {
          uni.showToast({
            title: this.i18n.insufficientStock,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        } else {
          uni.showToast({
            title: this.i18n.purchaseLimit + this.maxNum + this.i18n.piece,
            icon: 'none'
          });
        }
      } else {
        if (prodNum < this.defaultSku.stocks) {
          this.setData({
            prodNum: prodNum + 1
          });
        } else {
          uni.showToast({
            title: this.i18n.insufficientStock,
            icon: 'none',
            duration: 1000,
            mask: true
          })
        }
      }
    },
    /**
     * 通过商品id获取商品所有促销活动
     */
    getPordDiscountList () {
      http.request({
        url: "/marking/discount/getDiscountByProdId",
        method: "GET",
        data: {
          prodId: this.prodId
        },
        callBack: res => {
          this.setData({
            prodDiscountList: res
          });
        }
      });
    },

    /**
     * 促销活动弹窗
     */
    clickDiscount: function () {
      util.tapLog(3)
      var showDiscountPopup = !this.showDiscountPopup;
      if (this.isPlaying) {
        this.stopPlay()
      }
      this.setData({
        showDiscountPopup
      });
    },

    /**
     * 优惠券
     */
    showPopup: function () {
      util.tapLog(3)
      if (this.isPlaying) {
        this.stopPlay()
      }
      if (this.loadCouponIds) {
        this.setData({
          popupShow: true
        });
        return;
      }
      util.checkAuthInfo(() => {
        http.request({
          url: "/p/myCoupon/listCouponIds",
          method: "GET",
          data: {},
          callBack: myCouponList => {
            var couponList = this.couponList;
            couponList.forEach(coupon => {
              if (myCouponList && myCouponList.length) {
                // 领取该优惠券数量
                var couponLimit = 0
                // 改用户是否有可以使用的优惠券
                var isMyUseCoupon = false
                myCouponList.forEach(myCouponItem => {
                  if (myCouponItem.couponId == coupon.couponId) {
                    couponLimit = couponLimit + myCouponItem.curUserReceiveCount
                    if (myCouponItem.status == 1 && myCouponItem.curUserReceiveCount > 0) {
                      isMyUseCoupon = true
                    }
                  }
                });

                // 判断用户是否到达领取优惠券上限
                if (couponLimit < coupon.limitNum) {
                  coupon.canUse = true
                  coupon.canReceive = true
                } else {
                  coupon.canReceive = false
                  // 判断领取优惠券到达上限后,该种优惠券如果没有可用优惠券,则不可领取和使用
                  if (isMyUseCoupon == false) {
                    coupon.canUse = false
                  } else {
                    coupon.canUse = true
                  }
                }
              } else {
                coupon.canUse = true
                coupon.canReceive = true
              }
            });
            this.setData({
              couponList: couponList,
              popupShow: true,
              loadCouponIds: true
            })
          }
        });
      });
    },
    showSku: function (type = true) {
      util.tapLog(3)
      if (this.isPlaying) {
        this.stopPlay()
      }
      this.setData({
        skuShow: true,
        skuShowType: (this.isGroupProd && type ? 1 : 0)
      });
    },
    showGroupSku: function () {
      util.tapLog(3)
      if (this.isPlaying) {
        this.stopPlay()
      }
      if (this.groupActivity.activityStatus === 1) {
        uni.showToast({
          title: this.i18n.actNotBegin,
          icon: 'none',
        })
        return
      }
      this.setData({
        skuShow: true,
        skuShowType: 1
      });
    },
    // 显示评论页面
    showComment: function (e) {
      util.tapLog(3)
      if (this.isPlaying) {
        this.stopPlay()
      }
      this.setData({
        commentShow: true,
        evaluate: e,
        prodCommPage: {
          current: 0,
          pages: 0,
          records: []
        },
      });
      this.getProdCommPage();
    },
    closePopup: function () {
      util.tapLog(3)
      this.setData({
        popupShow: false,
        skuShow: false,
        commentShow: false
      });
    },
    onShowShare: function () {
      if (this.isPlaying) {
        this.stopPlay()
      }
      util.tapLog(3)
      this.setData({
        shareShow: true
      });
    },

    /**
     * 回到顶部
     */
    backToTop: function () {
      util.tapLog(3)
      uni.pageScrollTo({
        scrollTop: 0,
        duration: 300
      })
    },

    /**
     * 监听页面滚动
     */
    onPageScroll: function (e) {
      this.scrollTop = e.scrollTop
      if (this.scrollTop > 80) {
        this.setData({
          showBacktop: true
        });
      } else if (this.scrollTop < 80) {
        this.setData({
          showBacktop: false
        });
      }
    },
    closeEarn: function () {
      util.tapLog(3)
      this.setData({
        shareShow: false
      });
    },
    toDistCenterPage: function () {
      util.tapLog(3)
      uni.navigateTo({
        url: '/pages/dis-center/dis-center'
      });
    },

    /**
     * 生成小程序二维码
     */
    genWeixinCode () {
      var cardNo = wx.getStorageSync("distCardNo");
      var content = JSON.stringify({
        shareProdId: this.prodId,
        cardNo: cardNo
      });

      // #ifdef H5 || APP-PLUS
      let code = `${config.domainAddress}/pages/prod/prod?prodid=${this.prodId}&cardno=${cardNo}`
      this.shareWxCode = Qr.createQrCodeImg(code, { size: 250 });
      this.wxCodeShow = true;
      this.shareShow = false
      // #endif

      let params = {
        url: "/qrcodeTicket/miniQrCode",
        method: "GET",
        responseType: 'arraybuffer',
        data: {
          content: content,
          type: 2
        },
        callBack: res => {
          // 微信小程序
          this.setData({
            wxCodeShow: true,
            shareShow: false,
            shareWxCode: "data:image/jpg;base64," + wx.arrayBufferToBase64(res)
          });
        }
      }

      // #ifdef MP-WEIXIN
      http.request(params);
      // #endif
    },

    /**
     * 关闭二维码弹窗
     */
    closeCodePopup () {
      util.tapLog(3)
      this.setData({
        wxCodeShow: false
      });
    },

    /**
     * 保存图片至相册
     */
    downloadImg () {
      util.tapLog(3)
      uni.showLoading({
        mask: true
      })
      // #ifdef APP-PLUS
      const bitmap = new plus.nativeObj.Bitmap('test')
      bitmap.loadBase64Data(
        this.shareWxCode,
        () => {
          const url = '_doc/' + new Date() + '.png'; // url建议用时间戳命名方式
          bitmap.save(
            url,
            {
              overwrite: true
            },
            i => {
              uni.saveImageToPhotosAlbum({
                filePath: url,
                success: () => {
                  uni.hideLoading()
                  this.wxCodeShow = false
                  uni.showToast({
                    title: this.i18n.downloadComplete,
                  })
                  bitmap.clear()
                }
              })
            },
            e => {
              uni.hideLoading()
              // alert('保存失败1111', JSON.stringify(e))
              bitmap.clear()
            }
          )
        },
        e => {
          // alert('保存失败2222', JSON.stringify(e))
          uni.hideLoading()
          bitmap.clear()
        }
      )
      // #endif
      // #ifdef MP-WEIXIN
      var cardno = wx.getStorageSync("distCardNo")
      wx.downloadFile({
        header: {
          'Authorization': wx.getStorageSync('token')
        },
        url: config.domain + "/p/distribution/qrCode/invitation?page=pages/prod/prod&scene=" + this.prodId + ',' +
          cardno,
        success: (res) => {
          uni.hideLoading()
          //图片保存到本地
          wx.getSetting({
            success: settingData => {
              let flag = settingData.authSetting['scope.writePhotosAlbum']
              if (flag === true || flag === undefined) {
                uni.saveImageToPhotosAlbum({
                  filePath: res.tempFilePath,
                  success: data => {
                    this.wxCodeShow = false
                    uni.showToast({
                      title: this.i18n.downloadComplete,
                      icon: 'success',
                      duration: 2000
                    })
                  },
                  fail: err => {
                    uni.showToast({
                      title: this.i18n.failedSaveTips,
                      icon: 'none',
                      duration: 2000
                    })
                  }
                })
              } else {
                wx.openSetting({
                  success: settingData => {
                    if (settingData.authSetting['scope.writePhotosAlbum']) {
                      uni.showToast({
                        title: this.i18n.failedSave,
                        icon: 'none',
                        duration: 2000
                      })
                    } else {
                      uni.showToast({
                        title: this.i18n.failedSaveTips,
                        icon: 'none',
                        duration: 2000
                      })
                    }
                  }
                })
              }
            }
          })
        }
      });
      // #endif
    },

    /**
     * 用户点击分享到微信小程序
     * @param {Object} sharedata 支付需要的参数
     * @param {Object} cb 成功回调
     * @param {Object} errorCb 失败回调
     */
    onShareWay () {
      var cardno = wx.getStorageSync("distCardNo");
      // console.log('点击微信分享，cardno：',cardno, '//','shareProdId：',this.shareProdId)
      var sharedata = {
        title: this.prodName, // 分享标题
        imgUrl: this.imgs[0], // 分享图标
        link: config.domainAddress + '/pages/prod/prod?prodid=' + this.prodId + '&cardno=' + cardno, // 分享链接
        // path: '/pages/prod/prod?prodid=' + this.shareProdId + '&cardno=' + cardno,
        desc: this.brief ? this.brief : this.i18n.shartTips, // 分享描述
        type: '', // 分享类型,music、video或link，不填默认为link
        dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
      };
      Wechat.callWexinShare(sharedata, () => {
        this.shareShow = false
        this.guideShare = true
      }, (failMsg) => {
      })
    },

    groupConfirmOrder: function () {
      if (!this.findSku) {
        return;
      }
      if (this.prodNum > this.defaultSku.stocks) {
        uni.showToast({
          title: this.i18n.insufficientStock,
          icon: 'none',
          duration: 1000,
          mask: true
        })
        return
      }
      uni.showLoading({
        mask: true
      }); // 查看是否授权
      util.checkAuthInfo(() => {
        util.tapLog(3)
        uni.setStorageSync('groupOrderItem', JSON.stringify({
          groupSkuId: this.defaultGroupSku.groupSkuId,
          prodCount: this.prodNum,
          groupTeamId: 0
        }))
        uni.navigateTo({
          url: '/package-activities/pages/group-confirm-order/group-confirm-order'
        });
      });
    },

    /**
     * 视频信息
     */
    getVideoInfo () {
      const params = {
        url: this.video + '?avinfo',
        callBack: res => {
          let time = Number(res.data.format.duration).toFixed(0);
          this.setData({
            videoDuration: time < 60 ? '00′' + time + '″' : parseInt(time / 60) + '′' + time % 60 + '″'
          });
        }
      }
      http.request(params)
    },

    /**
     * 视频播放/停止按钮
     */
    videoOper () {
      util.tapLog(3)
      if (this.isPlaying) {
        this.stopPlay()
      } else {
        this.startPlay()
      }
    },
    playEnd () {
      this.stopPlay()
    },

    startPlay () {
      this.setData({
        isPlaying: true,
      })
      setTimeout(() => {
        this.videoContext.seek(0)
        this.videoContext.play()
      }, 200)
    },
    stopPlay () {
      this.setData({
        isPlaying: false
      })
      setTimeout(() => {
        this.videoContext.seek(0)
        this.videoContext.stop()
      }, 200)
    },

    /**
     * 前往直播页面
     */
    toLivePage: function (e) {
      this.roomId = e.currentTarget.dataset.roomid // 填写具体的房间号
      this.url = e.currentTarget.dataset.url
      util.checkAuthInfo(this.toLivePlayer)
    },
    toLivePlayer: function () {
      let roomId = this.roomId
      let url = this.url
      if (this.isWechat) {
        if (this.liveRoomParams.length == 1) {
          // 开发者在直播间页面路径上携带自定义参数（如示例中的path和pid参数），后续可以在分享卡片链接和跳转至商详页时获取
          let customParams = encodeURIComponent(JSON.stringify({
            path: url
          }))
          uni.navigateTo({
            url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomId}&custom_params=${customParams}`
          }) // 其中wx2b03c6e691cd7370是直播组件appid不能修改
        } else {
          uni.navigateTo({
            url: '/pages/live-broadcast/live-broadcast?prodId=' + this.prodId,
          })
        }
      } else {
        uni.showToast({
          title: this.i18n.pleaseOpenInWechat,
          icon: 'none'
        })
      }
    },

    /**
     * 通过分享进入
     */
    saveShareLog () {
      let flowAnalysisLogDto = uni.getStorageSync('flowAnalysisLogDto')
      flowAnalysisLogDto.bizData = this.prodId
      http.saveLog(flowAnalysisLogDto, 2)
    }

  }
};
</script>
<style scoped lang="scss">
@import "./prod.css";
@import "./prod.scss";

.Mall4j {
  background-color: #f2f2f2;
  position: relative;
  width: 750 rpx;
  //height: 8668.60465116279 rpx;
  //overflow: hidden;
}
</style>
